package com.dyp.h2_demo.repository;

import com.dyp.h2_demo.entity.Person;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.query.Param;

import java.util.Optional;

public interface PersonRepository extends Repository<Person, Long> {
    Person save(Person person);

    // Step2: 在接口中按Spring Data JPA声明规范声明查询方法
    Optional<Person> findById(long id);

    @Modifying
    @Query("UPDATE Person p SET p.name = :name WHERE p.id = :id")
    void updateById(@Param("id") Long id, @Param("name") String name);
}